package onlinejudge.controller;

import java.io.File;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import onlinejudge.util.FileUtil;

@Controller
@RequestMapping("/fileUpload")
public class FileController {
	
	/**
	 * 图片上传
	 * @param areaImg
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/img")
	public String getImg(@RequestParam("imgFile") MultipartFile imgFile,HttpServletRequest request) {
		String path= request.getSession().getServletContext().getRealPath("/");
		path=path+"img"+File.separator+imgFile.getOriginalFilename();
		String imgUrl=new FileUtil().fileUpload(imgFile,path);
	//	imgUrl=imgUrl.replace("\\","/");	//json不允许存在\
		return "{\"code\":\"0\",\"msg\":\"success\",\"data\":\""+imgUrl+"\"}";
	}
}
